package com.photoeditor.demo.model.image.emoji;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;

import com.common.base.ComponentContext;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class StickerConstant {

    //sticker zip包下载的路径
    public static final String ZIP_DOWNLOAD_PATH = com.common.base.utils.FileUtil.getCacheDir(ComponentContext.getContext(), "sticker", true);

    //安装的Apk必须有这个action用于判断是不是sticker包
    public final static String STICKERS_FILTER_ACITON = "com.photoeditor.extra.sticker.others";

    public static final String EMOJI_APK_SVAE_PATH = com.common.base.utils.FileUtil.getCacheDir(ComponentContext.getContext(), "emoji", true);

    /**
     * 下载Emoji包的GP链接
     */
    public static final String EMOJI_GP_URL = "market://details?id=com.photoeditor.extra.emoji";

    /**
     * 用于保存上次的Emoji
     */
    public static final String PREF_KEY_DEFAULT_EMOJI = "pref_default_emoji_new";

    /**
     * 保存到perference的分隔符
     */
    public static final String SP = "#";

    /**
     * 一行Emoji的数目
     */
    public static final int DEFAULT_COL_NUM = 6;

    public static final int STASH_COL_NUM_AR = 3;

    public static final int DEFAULT_COL_NUM_OTHER = 4;

    /**
     * 一页Emoji的个数
     */
    public static final int DEFAULT_PAGE_EMOJI_NUM = 18;

    public static final int STASH_PAGE_EMOJI_NUM_AR = 6;

    public static final int DEFAULT_PAGE_EMOJI_NUM_OTHER = 8;

    /**
     * 安装的Emoji Apk的包名
     */
    public final static String APK_EMOJI_NAME = "Emoji";

    /**
     * 内置虚拟apk包名
     */
    public final static String APK_EMOJI_PKG_NAME = "com.photoeditor.extra.emoji";

    /**
     * 外部emoji包名
     */
    public final static String APK_EMOJI_PKG_NAME_ALL = "com.photolab.emoji";
    public final static String APK_EMOJI_PKG_NAME_ALL_URL = "https://play.google.com/store/apps/details?id=com.photolab.emoji&referrer=utm_source%3DPOTDCamera%26utm_medium%3Dicon%26utm_campaign%3DStickerPage";

    /**
     * 用于判断是不是新版本
     * 如果是新的版本则不用处理  如果不是新版本则第二页现实更新跳转GP
     */
    public final static int EMOJI_PKG_VERSION_CODE = 4;


    /**
     * 未安装的Emoji Apk的包名
     */
    public final static String[] UNINSTALL_APK_PKG_NAME = new String[]{
    };

    /**
     * 未安装的Emoji Apk的下载地址
     */
    public final static String[] UNINSTALL_APK_DOWNURL = new String[]{
    };

    public static final String[] UNINSTALL_APK_NAME = new String[]{
    };

    public static final String[] UNINSTALL_NAME = new String[]{
    };

    public final static int[] BUTTON_ICON = new int[]{
//            R.drawable.baby_seal_icon,
//            R.drawable.ice_cream_icon,
//            R.drawable.christmas_icon,
//            R.drawable.candy_icon,
//            R.drawable.crazy_hamster_icon
    };

    /**
     * 用于判断Emoji包的版本是不是新的
     * @param context
     * @return 返回true标识版本符合要求
     */
    public static boolean isNewVersion(Context context){
        boolean ok = false;
        try {
            int versionCode = context.getPackageManager().getPackageInfo(StickerConstant.APK_EMOJI_PKG_NAME, 0).versionCode;
            if (versionCode >= EMOJI_PKG_VERSION_CODE) {
                ok = true;
            }
        } catch (Throwable e) {

        }
        return ok;
    }

    public static List<ResolveInfo> getAllInstalledStickerApk(Context context){
        PackageManager pm = context.getPackageManager();
        Intent shareIntent = new Intent(StickerConstant.STICKERS_FILTER_ACITON);
        try {
            return pm.queryIntentActivities(shareIntent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT);
        } catch (Exception e) {

        }
        return new ArrayList<>();
    }

    public static String getZIPDownloadPath(){
        File file = new File(ZIP_DOWNLOAD_PATH);
        if(!file.exists()){
            file.mkdirs();
        }
        return ZIP_DOWNLOAD_PATH;
    }
}
